<!DOCTYPE html>
<html>
<head>
    <include file="./public/sty.html"/>
    <style>
        .yz1,.yz2{text-align: left !important; margin-left: 20px;}
        .yz1 :before,.yz2 :before{ font-family: iconfont;
            font-style: inherit;
            padding: 0 5px;
            font-size: 14px;content: "\E60D";}
        .nbc{background:#2e4158; color:#fff;}
    </style>
</head>
<body>
<div id="app" class="setMail">
    <include file="./public/header.html"/>
    <form action="{:U('Users/setMail')}" method="get" id="form">
    <div class="container notSign fix pt15" s="[object Object]">
        <input type="hidden" name="id" id="uid" value="{$id}">
        <div class="userMain mgb10">
            <ul data-v-d8777e4e="" class="queue">
                <li data-v-d8777e4e="" class="right"><span data-v-d8777e4e="">选择验证方式</span><i data-v-d8777e4e=""></i></li>
                <li data-v-d8777e4e="" class="now"><span data-v-d8777e4e="">验证邮箱</span><i data-v-d8777e4e=""></i></li>
                <li data-v-d8777e4e=""><span data-v-d8777e4e="">设置密码</span><i data-v-d8777e4e=""></i></li>
                <li data-v-d8777e4e=""><span data-v-d8777e4e="">完成</span><i data-v-d8777e4e=""></i></li>
            </ul>
            <ul class="submitContent mglr30 mgt15">
                <li><span>邮箱：</span> <input tag="邮箱" id="email" placeholder="请输入您要绑定的邮箱地址" type="text" class="userInput"><span class="yz1" style="width: 300px"></span>  <!---->
                </li>
                <li style="position: relative;"><span>验证码：</span>
                    <input tag="验证码" placeholder="输入验证码" id="yzm" type="text" class="userInput">
                    <span class="yz2" style="width: 300px"></span> <!---->
                    <span class="btn SendCode"><a class="ClickShade nbc nbc2" onclick="examine()">发送验证码</a></span>
                </li>
                <li><span></span> <a class="submitBtn ClickShade" onclick="sav()">确定</a></li>
            </ul>
        </div>
    </div>
 </form>

    <div id="tishi1" class="layermbox layermbox0 layermshow" index="11">
        <div class="laymshade"></div>
        <div class="layermmain">
            <div class="section">
                <div class="layermchild layerConfirm layermanim"><h3 style="">温馨提示</h3>
                    <button class="layermend"></button>
                    <div class="layermcont">·发送成功，请注意查收·</div>
                    <div class="layermbtn"><span type="1">确定</span></div>
                </div>
            </div>
        </div>
    </div>
    <div id="tishi2" class="layermbox layermbox0 layermshow" index="11">
        <div class="laymshade"></div>
        <div class="layermmain">
            <div class="section">
                <div class="layermchild layerConfirm layermanim"><h3 style="">温馨提示</h3>
                    <button class="layermend"></button>
                    <div class="layermcont">·发送失败·</div>
                    <div class="layermbtn"><span type="1">确定</span></div>
                </div>
            </div>
        </div>
    </div>
    <include file="./public/footer.html"/>
</div>


<script src="/style/js/jquery.min.js"></script>
<script src="/style/js/fx.js"></script>
<script>
    $(function(){
        personalInfo();
    })
</script>
</body>
</html>

<script>
    function sav(){
        var id = $("#uid").val();
        var email = $("#email").val();
        var yzm = $("#yzm").val();
        if(email == ''){
            $(".yz1").html("<font color='red'>邮箱不能为空</font>");
            return false;
        }else {
            $(".yz1").html("");
        }
        var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
        if(!reg.test(email)) {
            $(".yz1").html("<font color='red'>邮箱格式不正确，请重新输入！</font>");
            return false;
        }else{
            $(".yz1").html("");
        }


        if(yzm == ''){
            $(".yz2").html("<font color='red'>验证码不能为空</font>");
            return false;
        }else {
            $(".yz2").html("");
        }
        $.ajax({
            type: "POST",
            url: "{:U('Index/setMail')}",
            data: {'yzm':yzm,'email':email,'id':id},
            success: function(dat){
                if(dat==1){
                    window.location.href = "/Index/verifyPwd5/id/"+id;
                }else{
                    $(".yz2").html("<font color='red'>验证码错误，请重新输入</font>");
                }
            }
        });
    }

    function examine(){
        var id = $("#uid").val();
        var email = $("#email").val();
        if(email == ''){
            $(".yz1").html("<font color='red'>邮箱不能为空</font>");
            return false;
        }else {
            $(".yz1").html("");
        }

        $.ajax({
            type:"post",
            url:"{:U('Index/examine_message2')}",
            data:{'email':email,'id':id},
            dataType:"json",
            success:function(msg){
                if(msg==2){
                    $(".yz1").html("<font color='red'>邮箱错误，请重新输入</font>");
                }else if(msg==1){
//                    alert("发送成功，请注意查收");
                    $("#tishi1").show();
                    var t = 60;
                    $(".nbc2").html(t+" s");
                    var timer = setInterval(function(){
                        t--;
                        $(".nbc2").html(t+" s");
                        if(t <= 0){
                            clearInterval(timer);
                            $(".nbc2").addClass("nbc");
                            $(".nbc2").html("发送验证码");
                        }
                    },1000);
                    $(".nbc2").removeClass("nbc");
                }else{
                    $("#tishi2").show();
                }
            }
        })
    }
</script>